﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication2.Model
{
    class TransaksiLayanan
    {
        public int id;
        int idTransaksi;
        int idKaryawan;
        int idLayananCabang;
        int kualitas;
        int idPromo;
        int idFreeGift;
        int harga;
        string status;

        public TransaksiLayanan()
        {
            
        }

        public TransaksiLayanan(int _id)
        {
            Database db = new Database();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM transaksi_layanan WHERE id = '" + _id + "'";

            db.Open();
            ds = db.ExecuteQuery(sql);
            dt = ds.Tables[0];
            DataRow dr = dt.Rows[0];

            id = (int)dr[0];
            
            db.Close();
        }

        public ArrayList DaftarTransaksiLayanan(int _Cabang)
        {
            return null;
        }

        public void AddTransaksiLayanan(int _idTransaksi, int _idKaryawan, int _idLayananCabang)
        {
            Database db = new Database();
            long l;
            string sql = "INSERT INTO transaksi_layanan(\"ID_Transaksi\", \"ID_Karyawan\", \"ID_LayananCabang\", \"Status\") VALUES (" + _idTransaksi.ToString() + "," + _idKaryawan.ToString() +
                    "," + _idLayananCabang.ToString() + ", 'W');select currval('\"transaksi_layanan_ID_TransaksiLayanan_seq\"')";

            db.Open();
            l = db.ExecuteNonQuery(sql);
            db.Close();

            id = (int)l;
        }

        public void UpdateTransaksiLayanan(int _idTransaksiLayanan, int _idKaryawan)
        {
            Database db = new Database();
            string sql = "UPDATE transaksi_layanan SET \"ID_Karyawan\" = " + _idKaryawan.ToString() + " WHERE \"ID_Transaksi\" = " + _idTransaksiLayanan.ToString();

            db.Open();
            db.ExecuteDelete(sql);
            db.Close();
        }

        public void UpdateTransaksiLayanan(int _idTransaksiLayanan, int _idKaryawan, int _idLayananCabang)
        {
            Database db = new Database();
            string sql = "UPDATE transaksi_layanan SET \"ID_Karyawan\" = " + _idKaryawan.ToString() + ", \"ID_LayananCabang\" = " + _idLayananCabang.ToString() + " WHERE \"ID_Transaksi\" = " + _idTransaksiLayanan.ToString();

            db.Open();
            db.ExecuteDelete(sql);
            db.Close();
        }

        public void UpdateTransaksiLayanan(int _idTransaksiLayanan, int _idKaryawan, string _status)
        {
            Database db = new Database();
            string sql = "UPDATE transaksi_layanan SET \"ID_Karyawan\" = " + _idKaryawan.ToString() + ", \"Status\" = '" + _status + "' WHERE \"ID_Transaksi\" = " + _idTransaksiLayanan.ToString();

            db.Open();
            db.ExecuteDelete(sql);
            db.Close();
        }

        public void DeleteTransaksiLayanan(int _id)
        {
            Database db = new Database();
            string sql = "DELETE FROM transaksi_layanan WHERE \"ID_TransaksiLayanan\" = " + _id.ToString();

            db.Open();
            db.ExecuteDelete(sql);
            db.Close();
        }
    }
}
